﻿/*
 * The MIT License
 * 
 * Copyright 2008 Jeppe Burchardt and Pimm Hogeling
 *
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following
 * conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 */

package org.dr.actionconsole.utils
{
	import org.dr.actionconsole.Console;
	import org.dr.actionconsole.ConsoleTextColor;
	import org.papervision3d.core.log.AbstractPaperLogger;
	import org.papervision3d.core.log.IPaperLogger;
	public class ConsolePaperLogger extends AbstractPaperLogger implements IPaperLogger
	{
		/**
		 * All messages are shown.
		 */
		public static const LOG : uint = 5;
		/**
		 * Only "log" messages are ignored.
		 */
		public static const INFO : uint = 4;
		/**
		 * "log" and "info" messages are ignored.
		 */
		public static const DEBUG : uint = 3;
		/**
		 * Only "warning", "error" and "fatal" messages are shown.
		 */
		public static const WARNING : uint = 2;
		/**
		 * Only "error" and "fatal" messages are shown.
		 */
		public static const ERROR : uint = 1;
		/**
		 * Only "fatal" messages are shown.
		 */
		public static const FATAL : uint = 0;
		private var filter : uint;
		public function ConsolePaperLogger(filter:uint = LOG) : void
		{
			super();
			this.filter = filter;
		}
		public override function debug(message:String, object:Object=null, arguments:Array=null) : void
		{
			if (filter > WARNING)
			{
				Console.writeLine(ConsoleTextColor.BOLD, "Debug:", ConsoleTextColor.NORMAL, message);
			}
		}
		public override function error(message:String, object:Object=null, arguments:Array=null) : void
		{
			if (filter > FATAL)
			{
				Console.writeLine(ConsoleTextColor.ERROR, "Error:", ConsoleTextColor.NORMAL, message);
			}
		}
		public override function fatal(message:String, object:Object=null, arguments:Array=null) : void
		{
			Console.writeLine(ConsoleTextColor.ERROR, "Fatal:", ConsoleTextColor.NORMAL, message);
		}
		public override function info(message:String, object:Object=null, arguments:Array=null) : void
		{
			if (filter > DEBUG)
			{
				Console.writeLine(ConsoleTextColor.BOLD, "Info:", ConsoleTextColor.NORMAL, message);
			}
		}
		public override function log(message:String, object:Object=null, arguments:Array=null) : void
		{
			if (filter === LOG)
			{
				Console.writeLine(ConsoleTextColor.BOLD, "Log:", ConsoleTextColor.NORMAL, message);
			}
		}
		public override function warning(message:String, object:Object=null, arguments:Array=null) : void
		{
			if (filter > ERROR)
			{
				Console.writeLine(ConsoleTextColor.ERROR, "Warning:", ConsoleTextColor.NORMAL, message);
			}
		}
	}
}